#include <iostream>
#include <cstdio>
#include <cerrno>
#include <cstring>
#include <cassert>
#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "head.hpp"

int main(){
    int rfd = open(pipeName.c_str(), O_RDONLY);
    if(rfd < 0){
        cout << errno << ": " << strerror(errno) << endl;
        return 1;
    }

    char buffer[NUM];
    while(true){
        buffer[0] = 0;
        ssize_t n = read(rfd, buffer, sizeof(buffer) - 1);
        if(n > 0){
            buffer[n] = 0;
            cout << buffer << endl;
        }
        else if(n == 0){
            cout << "client quit, me too" << endl;
            break;
        }
        else{
            cout << errno << ": " << strerror(errno) << endl;
            break;
        }
    }

    close(rfd);
    unlink(pipeName.c_str());
}